home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / nasanets.zip / COMMON.H < prev    next >
C/C++ Source or Header  |  1990-06-07  |  12KB  |  329 lines

  1.  
  2. /*=============================*/
  3. /*           NETS              */
  4. /*                             */
  5. /* a product of the AI Section */
  6. /* NASA, Johnson Space Center  */
  7. /*                             */
  8. /* principal author:           */
  9. /*       Paul Baffes           */
  10. /*                             */
  11. /* contributing authors:       */
  12. /*      Bryan Dulock           */
  13. /*      Chris Ortiz            */
  14. /*=============================*/
  15.  
  16.  
  17. /*
  18. ----------------------------------------------------------------------
  19.   COMMON DATA MODULE  
  20. ----------------------------------------------------------------------
  21.   This module has all of the types which are global to the neural  
  22.    net system, but which are not part of any particular structure  
  23.    within the net.  Global constants, flags, time variables, etc   
  24.    are the kinds of things which get declared here.  I guess you   
  25.    can think of this as the global area for the overall program.   
  26.   Some notes on nomenclature:  Capitalized letters are used here   
  27.    for types which are declared for this program.  If those type   
  28.    definitions are not here, they will be in a file that goes with 
  29.    this system (ie, either: 'net.h' 'layer.h' or 'weights.h')      
  30.   Also, note that the other include.h files are included at the    
  31.    bottom of this file.  This is done so that the '.c' files need  
  32.    only include this file to get their hands on everything.        
  33. -------------------------------------------------------------------
  34. */
  35.  
  36.  
  37. /*
  38. -------------------------------------------------------------------
  39.   PORTABILITY SPECIFICATION
  40. -------------------------------------------------------------------
  41.   Set only ONE of the constants below to "1" depending upon which 
  42.   machine/compiler you are using. Set the rest to "0" (zero).
  43. -------------------------------------------------------------------
  44. */
  45.  
  46. #define VMS              0
  47. #define IBM_MSC          0
  48. #define IBM_TBC          1
  49. #define LSPEED           0
  50. #define UNIX_ATT         0
  51. #define UNIX_BER         0
  52. #define WIZARD           0
  53.  
  54.  
  55. /*
  56. -------------------------------------------------------------------
  57.   DELIVERY SPECIFICATION
  58. -------------------------------------------------------------------
  59.   Set the "DELIVERY" constant to "0" (zero) when compiling NETS in 
  60.   the normal mode. Set it to "1" when compiling delivery code.
  61. -------------------------------------------------------------------
  62. */
  63. #define DELIVERY         0
  64.  
  65.  
  66. /*
  67. -------------------------------------------------------------------
  68.   SCALED INTEGER SPECIFICATION
  69. -------------------------------------------------------------------
  70.   If the Sint (Scaled Integer) format is desired, set the constant
  71.   below to "1". Otherwise, setting the constant to "0" (zero) will
  72.   cause NETS to use floating point format. The Sint format runs 
  73.   much faster on most machines, but has less precision.
  74. -------------------------------------------------------------------
  75. */
  76. #define USE_SCALED_INTS  1
  77.  
  78.  
  79.  
  80. /*
  81. -------------------------------------------------------------------
  82.   INCLUDE FILES
  83. -------------------------------------------------------------------
  84.   Below are the include files needed by each of the various compilers.
  85. -------------------------------------------------------------------
  86. */
  87.  
  88. #include  <stdio.h>      /* standard include files for C programs    */
  89. #include  <math.h>
  90.  
  91. #if   VMS
  92. #include <timeb>
  93. #endif
  94.  
  95. #if   IBM_MSC
  96. #include <fcntl.h>
  97. #include <sys\types.h>
  98. #include <sys\stat.h>
  99. #include <io.h>
  100. #include <conio.h>
  101. #include <malloc.h>
  102. #include <sys\timeb.h>
  103. #endif
  104.  
  105. #if   UNIX_ATT
  106. #include <sys/types.h>
  107. #include <sys/times.h>
  108. #endif
  109.  
  110. #if   UNIX_BER
  111. #include <sys/types.h>
  112. #include <sys/timeb.h>
  113. #endif
  114.  
  115. #if  IBM_TBC
  116. #include <stdlib.h>
  117. #include <time.h>
  118. #include <dos.h>
  119. #include <alloc.h>
  120. #endif
  121.  
  122. #if  WIZARD
  123. #include <stdlib.h>
  124. #include <time.h>
  125. #include <system.h>
  126. #include <string.h>
  127. pragma Off (Char_default_unsigned);
  128. #endif
  129.  
  130. #if  LSPEED
  131. #include <unix.h>
  132. #include <storage.h>
  133. #include <time.h>
  134. #endif
  135.  
  136.  
  137. /*
  138. -------------------------------------------------------------------
  139.   COMMON DEFINITIONS
  140. -------------------------------------------------------------------
  141.   This section contains the rest of the constant definitions needed
  142.   in common across all the files in NETS.
  143. -------------------------------------------------------------------
  144. */
  145.  
  146.       /*--------------------------------------------------*/
  147.       /* first some redefinitions of "{" and "}" to help  */
  148.       /* me keep track of my begins and ends              */
  149.       /*--------------------------------------------------*/
  150.       
  151. #define BEGIN       {    /* English versions of the familiar "{" and */
  152. #define END         }    /* "}" tokens of C.                         */
  153. #define ENDIF       }
  154. #define ENDFOR      }
  155. #define ENDELSE     }
  156. #define ENDCASE     }
  157. #define ENDWHILE    }
  158. #define ENDSWITCH   }
  159.  
  160.       /*--------------------------------------------------*/
  161.       /* Next, SEEK_SET is defined for use by the funct.  */
  162.       /* "fseek" (see pairs.c). Some compilers predefine. */
  163.       /*--------------------------------------------------*/
  164.  
  165. #ifndef  SEEK_SET
  166. #define  SEEK_SET   0
  167. #endif
  168.  
  169.       /*--------------------------------------------------*/
  170.       /* Definitions for the scaled integer format which  */
  171.       /* I call "Sint."  Note that Sints are assumed to   */
  172.       /* be 2 bytes on all machines, thus the definitions */
  173.       /* for each machine are changed appropriately. Also */
  174.       /* note that a Sint is an int with 10 bits assumed  */
  175.       /* after the decimal. That's 2^10 = 1024 which is   */
  176.       /* a constant needed during conversion operations.  */
  177.       /* (also, see below for Sint type definitions).     */
  178.       /*--------------------------------------------------*/
  179.  
  180. #define SINT_BYTES   2 
  181. #define SINT_SCALE   1024 
  182. #define SCALE_LOG2   10      /* log base 2 of the SINT_SCALE value */
  183. #define MAX_SINT     32000
  184. #define MIN_SINT    -32000
  185. #if  USE_SCALED_INTS
  186. #define WTS_SCALE    1000    /* Should be set to 1 * 10^precision, where */
  187.                              /* precision = number of sig figs after the */
  188.                              /* decimal point in a Sint.                 */
  189. #else
  190. #define WTS_SCALE    100000  /* more precision with floating points      */
  191. #endif
  192.  
  193.       /*--------------------------------------------------*/
  194.       /* There are several constants needed to define the */
  195.       /* various network parameters such as layer size,   */
  196.       /* type of connectivity between layers, and limits  */
  197.       /* imposed during learning. Most notable is the     */
  198.       /* MAX_NODES constant which is defined differently  */
  199.       /* depending upon whether Sint or float format is   */
  200.       /* used. Normally, 32K would be the upper limit due */
  201.       /* the limit if 16-bit ints, but 10K turns out to   */
  202.       /* be practical if Sints are used. Anything above   */
  203.       /* 10K produces numbers past the precision of Sints */
  204.       /*--------------------------------------------------*/
  205.  
  206. #define MAX_LAYERS   20
  207. #define IN_LAYER     0
  208. #define OUT_LAYER    1 
  209.  
  210. #if   USE_SCALED_INTS
  211. #define MAX_NODES    10000 
  212. #else
  213. #define MAX_NODES    32000 
  214. #endif
  215.  
  216. #define PATTERNED    11     /* For patterned connection schemes */
  217. #define CONNECT_ALL  21     /* For fully-connected layers       */
  218. #define MAX_CYCLES   10000  /* Most cycles allowed during learning */  
  219.                          
  220.       /*--------------------------------------------------*/
  221.       /* Below are some constants for the two different   */
  222.       /* file formats which NETS produces. The first two  */
  223.       /* constants indicate which format to print. Then   */
  224.       /* come two signature constants which are used to   */
  225.       /* tell binary format from text format. That is, if */
  226.       /* a binary format is specified but a text file is  */
  227.       /* given as the argument, the first read will not   */
  228.       /* reveal the signature thus an error will be cited */
  229.       /* Note that different signatures are used for the  */
  230.       /* Sint and float formats. The signature numbers    */
  231.       /* don't mean anything, they're just low numbers of */
  232.       /* the ascii table.                                 */
  233.       /*--------------------------------------------------*/
  234.  
  235. #define PORTABLE_FORMAT  1   /* Flag for ASCII load/save of weights  */
  236. #define FAST_FORMAT      0   /* Flag for BINARY load/save of weights */
  237.  
  238. #if  USE_SCALED_INTS
  239. #define  BIN_SIG         0x1701    /* Star Trek Enterprize number */
  240. #define  WRONG_SIG       0x1812    /* Famous battle date          */
  241. #else
  242. #define  BIN_SIG         0x1812    /* reverse if in float format  */
  243. #define  WRONG_SIG       0x1701   
  244. #endif
  245. #define  SIG_SIZE        2         /* all signatures are 2 bytes  */
  246.                                
  247.       /*--------------------------------------------------*/
  248.       /* Miscellaneous constant definitions.              */
  249.       /*--------------------------------------------------*/
  250.  
  251. #define MAX_SUM       7000  /* values over this always produce an */
  252.                             /* activation = 1 when using Sint     */
  253. #define MAX_LINE_SIZE  256  /* for input buffers */
  254. #define MAX_DISPLAY     19  /* Number of lines printed per screen */
  255. #define MAX_WORD_SIZE   75  /* the longest unbroken chain of chars */
  256.                             /* allowed in an input file, where     */
  257.                             /* 'unbroken' is defined by the white  */
  258.                             /* space characters above.             */ 
  259.  
  260. #define TRUE          1
  261. #define FALSE         0
  262.  
  263. #define ERROR        -13
  264. #define OK            1
  265. #define UNDEFINED    -1     /* says global_learn_rate/momentum haven't */
  266.                             /* been set to anything in net spec file   */
  267.  
  268. #ifndef  PI                            /* if not defined, define PI */
  269. #define  PI  (3.14159265358979323846)  /* for use in lnrate.c file  */
  270. #endif                                 /* when doing FLOAT not Sint */
  271.  
  272.  
  273. /*
  274. -------------------------------------------------------------------
  275.   COMMON TYPEDEF'S
  276. -------------------------------------------------------------------
  277.   Below are the type definitions for NETS. Using typedefs allows 
  278.   most of the code to remain the same regardless of which machine
  279.   is used. Rather than depending upon the whim of the integer size
  280.   of the machine, the code simply uses the type definitions made
  281.   here. Thus, machine dependencies can be taken care of in one place.
  282. -------------------------------------------------------------------
  283. */
  284.  
  285.       /*--------------------------------------------------*/
  286.       /* First the scaled integer typedefs. It is assumed */
  287.       /* that Sints are 2 bytes long, which means using   */
  288.       /* the short int format. If floats are desired, the */
  289.       /* "Sint" typedef is simply a renaming of "float."  */
  290.       /* For multiplication reasons, double sized sints   */
  291.       /* or D_Sints are needed (ie, you can't multiply 2  */
  292.       /* short ints together and always end up with a     */
  293.       /* a short, thus longs are used). Again, if floats  */
  294.       /* are desired, D_Sint = float.                     */
  295.       /*--------------------------------------------------*/
  296.  
  297. #if    USE_SCALED_INTS
  298. typedef short int Sint;
  299. #else           
  300. typedef float  Sint;
  301. #endif
  302.  
  303. #if  USE_SCALED_INTS && (IBM_MSC || IBM_TBC || LSPEED)
  304. typedef long int D_Sint;
  305. #endif
  306. #if  USE_SCALED_INTS && (VMS || UNIX_ATT || UNIX_BER || WIZARD)    
  307. typedef int D_Sint;
  308. #endif
  309. #if  !USE_SCALED_INTS
  310. typedef float  D_Sint;
  311. #endif
  312.  
  313.       /*--------------------------------------------------*/
  314.       /* Finally, I also define 16-bit and 32-bit ints so */
  315.       /* that I can guaranty specific sizes when needed.  */
  316.       /* This allows NETS to save memory on big machines  */
  317.       /*--------------------------------------------------*/
  318.  
  319. #if  IBM_MSC || IBM_TBC || LSPEED
  320. typedef int int16;
  321. typedef long int int32;
  322. #endif 
  323. #if  VMS || UNIX_ATT || UNIX_BER || WIZARD
  324. typedef short int int16;
  325. typedef int int32;
  326. #endif
  327.  
  328.  
  329.